package widget.book.utils
{
	import flash.geom.Point;
	
	import widget.book.manager.BookManager;
	import widget.book.viewer.BasePageViewer;
	import widget.book.viewer.FlipMaskViewer;
	import widget.book.viewer.ShadowViewer;
	import widget.common.utils.MathUtils;

	public class BookUtils{
		public function BookUtils()
		{
		}
		
		/**
		 * @function	rotateFlip
		 * @param	flip		页面实例MC
		 * @param	mPoint		鼠标的坐标值
		 * @param	hPoint		水平方向折角的坐标值
		 * @param	vPoint		垂直方向折角的坐标值
		 * @param	fPoint		第四个角的坐标值
		 * @param	area		鼠标所在的热区
		 * @usage	根据mousepoint,hpoint,vpoint,fpoint以及鼠标所在的热区,变换页面的角度
		 */
		public static function rotateFlip(flip:BasePageViewer,masker:FlipMaskViewer,shadow:ShadowViewer, mPoint:Point,area:Number) {
			var rotation:Number;
			var maskPoint:Point=new Point();
			var maskScaleX:Number;
			var maskScaleY:Number;
			var bookSize:Point = new Point(BookManager.getInstance().bookModel.width,BookManager.getInstance().bookModel.height);
			switch (area) {
				case 0:
					rotation = MathUtils.angle(mPoint.x - 0, mPoint.y - 0);
					maskPoint.x = MathUtils.distance(mPoint.x, mPoint.y, 0, 0)/2/Math.cos(rotation * Math.PI / 180);
					maskPoint.y = 0;
					maskScaleX = 1;
					break;
				case 1:
					rotation = MathUtils.angle(mPoint.x - bookSize.x, mPoint.y - 0);
					maskPoint.x = bookSize.x - MathUtils.distance(mPoint.x, mPoint.y, bookSize.x, 0)/2/Math.cos(rotation * Math.PI / 180);
					maskPoint.y = 0;
					maskScaleX = -1;
					break;
				case 2:
					rotation = MathUtils.angle(mPoint.x - 0, mPoint.y - bookSize.y);
					maskPoint.x = MathUtils.distance(mPoint.x, mPoint.y, 0, bookSize.y)/2/Math.cos(rotation * Math.PI / 180);
					maskPoint.y = bookSize.y;
					maskScaleX = 1;
					break;
				case 3:
					rotation = MathUtils.angle(mPoint.x - bookSize.x, mPoint.y - bookSize.y);
					maskPoint.x =bookSize.x - MathUtils.distance(mPoint.x, mPoint.y,bookSize.x, bookSize.y)/2/Math.cos(rotation * Math.PI / 180);
					maskPoint.y = bookSize.y;
					maskScaleX = -1;
					break;
			}
			flip.x = mPoint.x;
			flip.y = mPoint.y;
			flip.rotation = 2 * rotation;
			
			masker.x = maskPoint.x;
			masker.y = maskPoint.y;
			masker.scaleX = maskScaleX;
			masker.rotation = rotation;
			
			shadow.setUp(mPoint, maskPoint, rotation, masker.scaleX,area);
		}
	}
}